"use strict";
cc._RF.push(module, '5fb96m8uRNOupuZ7ERyScgw', 'GameDB');
// script/poker_project/gameView/GameDB.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Poker = void 0;
var ConfigEnum_1 = require("../ConfigEnum");
var GameEvent_1 = require("./GameEvent");
var SplashScene_1 = require("../SplashScene");
var Poker = /** @class */ (function () {
    function Poker(point, suit, pokerstatus) {
        this.point = -1;
        this.suit = ConfigEnum_1.Esuit.HEITAO; //花色
        this._status = ConfigEnum_1.EPokerStatus.CLOSE;
        this._view = null;
        this.point = point;
        this.suit = suit;
        this._status = pokerstatus;
    }
    Object.defineProperty(Poker.prototype, "status", {
        get: function () {
            return this._status;
        },
        set: function (value) {
            this._status = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Poker.prototype, "view", {
        get: function () {
            return this._view;
        },
        enumerable: false,
        configurable: true
    });
    Poker.prototype.Bind = function (view) {
        this._view = view;
    };
    Poker.prototype.UnBind = function () {
        this._view = null;
    };
    return Poker;
}());
exports.Poker = Poker;
var PokerGroup = /** @class */ (function () {
    function PokerGroup() {
        this._pokers = [];
    }
    PokerGroup.prototype.AddPoker = function (poker) {
        this._pokers.push(poker);
    };
    Object.defineProperty(PokerGroup.prototype, "pokers", {
        get: function () {
            return this._pokers;
        },
        enumerable: false,
        configurable: true
    });
    return PokerGroup;
}());
//裁判，隶属于GameScene,牌局管理者，准备好扑克牌，桌子等等
var GameDB = /** @class */ (function () {
    /*******************************************************************************
     * Private API
     ******************************************************************************/
    function GameDB() {
        this.m_GameCtrl = null;
        /*********************************************************************************
         * property
         ******************************************************************************/
        this._pokers = [];
        //发牌区
        this._closeAreaPokers = [];
        this._openAreaPokers = [];
        //收牌区
        this._receiveAreaPokerGroups = [];
        //玩牌区
        this._playAreaPokerGroups = [];
        //初始化牌局结构
        for (var i = 0; i < GameDB.CONST_RECEIVE_GROUPS; i++) {
            var pokerGroup = new PokerGroup();
            this._receiveAreaPokerGroups.push(pokerGroup);
        }
        for (var i = 0; i < GameDB.CONST_PLAY_GROUPS; i++) {
            var pokerGroup = new PokerGroup();
            this._playAreaPokerGroups.push(pokerGroup);
        }
        //初始化扑克牌
        for (var point = 1; point <= 13; point++) {
            for (var suit = 0; suit < 4; suit++) {
                var poker = new Poker(point, suit, ConfigEnum_1.EPokerStatus.CLOSE);
                this._pokers.push(poker);
            }
        }
        //初始化牌局事件
        SplashScene_1.default.eventTarget.emit(GameEvent_1.default.INIT_POKER, this._pokers);
    }
    Object.defineProperty(GameDB.prototype, "pokers", {
        /*******************************************************************************
         * getter & setter
         ******************************************************************************/
        get: function () {
            return this._pokers;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(GameDB.prototype, "receiveAreaPokerGroups", {
        get: function () {
            return this._receiveAreaPokerGroups;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(GameDB.prototype, "playAreaPokerGroups", {
        get: function () {
            return this._playAreaPokerGroups;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(GameDB.prototype, "closeAreaPokers", {
        get: function () {
            return this._closeAreaPokers;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(GameDB.prototype, "openAreaPokers", {
        get: function () {
            return this._openAreaPokers;
        },
        enumerable: false,
        configurable: true
    });
    /*******************************************************************************
     * Public static API
     ******************************************************************************/
    GameDB.Create = function () {
        var gameDB = new GameDB();
        return gameDB;
    };
    /*******************************************************************************
     * Public API
     ******************************************************************************/
    GameDB.prototype.Play = function () {
        //洗牌
        this.shuffle(this._pokers, 500);
        // 移动牌
        var tmp = this._closeAreaPokers;
        this._closeAreaPokers = this._pokers;
        this._pokers = tmp;
        //通知UI层，发生变化
        SplashScene_1.default.eventTarget.emit(GameEvent_1.default.PLAY, this._pokers);
        //发牌
        for (var cards = GameDB.CONST_PLAY_GROUPS; cards >= 1; cards--) {
            for (var i = 0; i < cards; i++) {
                var cardGroupIndex = GameDB.CONST_PLAY_GROUPS - cards + i;
                var cardGroup = this._playAreaPokerGroups[cardGroupIndex];
                var poker = this._closeAreaPokers[this._closeAreaPokers.length - 1];
                this._closeAreaPokers.length = this._closeAreaPokers.length - 1;
                poker.status = i === 0 ? ConfigEnum_1.EPokerStatus.OPEN : ConfigEnum_1.EPokerStatus.CLOSE;
                // console.info("发牌",poker.point,poker.suit,poker.status)
                cardGroup.AddPoker(poker);
                SplashScene_1.default.eventTarget.emit(GameEvent_1.default.INIT_GROUP_CARD, cardGroupIndex, GameDB.CONST_PLAY_GROUPS - cards, poker);
            }
        }
    };
    /*******************************************************************************
     * Event handle
     ******************************************************************************/
    //洗牌
    GameDB.prototype.shuffle = function (pokers, count) {
        if (count === void 0) { count = 100; }
        for (var i = 0; i < count; i++) {
            var sIdx = parseInt('' + Math.random() * pokers.length, 10);
            var eIdx = parseInt('' + Math.random() * pokers.length, 10);
            var tmp = pokers[sIdx];
            pokers[sIdx] = pokers[eIdx];
            pokers[eIdx] = tmp;
        }
    };
    GameDB.prototype.OnEventClickPoker = function (poker) {
        console.log('当前牌：', poker);
    };
    GameDB.CONST_RECEIVE_GROUPS = 4;
    GameDB.CONST_PLAY_GROUPS = 7;
    return GameDB;
}());
exports.default = GameDB;

cc._RF.pop();